< previous page page_336 next page >

Page 336
e10a6a0a59f035e870d90cca05b85fce.gif
b = [(C * F - B * G) * (B * C - A * E) - (B * D - A * F) * (C * E - B *
N)] / [(B * C - A * E) * (C
2 - B * E) - (C * E - B * N) * (B2 - A * C)]

c = [(B * D - A * F) * (C
2 - B * E) - (C * F - B * G) * (B2 - A * C)] /
[(B * C - A * E) * (C
2 - B * E) - (C * E - B * N) * (B2 - A * C)]
You can use these equations to write a subroutine similar to the GetLeastSquaresValues routine described in the previous section for finding the least squares parameters. Example program LeastSq2 uses the new version of GetLeastSquaresValues to display quadratic least squares curves to fit sets of data points. Figure 11.10 shows program LeastSq2 in action.
Note that a straight line is a form of the quadratic function a * x2 + b * x + c, where the constant a = 0. If you compute the parameters for a quadratic least squares curve and the data points fall mostly along a straight line, the value you calculate for parameter a will be close to zero. This gives you a quadratic that is almost identical to the line you would have obtained had you used the linear least squares methods. In this sense, you have not lost anything by using the quadratic method. You will still find a more or less straight line if one fits the data well. Of course, you need to do a lot more work to find this curve using the quadratic method.
Higher-Order Least Squares
Using these same methods, you can fit polynomials of even higher degree to your collection of data points. Higher-degree polynomials can contain more bends, so they will tend to match your data values more closely.
You can write the equation for the polynomial function as:
e10a6a0a59f035e870d90cca05b85fce.gif
y = A0 + A1 * x + A2 * x2 + ... + AN * xN
0336-01.jpg
Figure 11.10
Program LeastSq2 fitting a quadratic to a set of points.

 
< previous page page_336 next page >